﻿using GC_FFW.ForecastWriter.Abstractions.Interfaces.Helpers;
using System.Collections.Generic;
using System.Linq;
using GC_FFW.ForecastWriter.Common;

namespace GC_FFW.ForecastWriter.Helpers
{
	public class StringManager : IStringManager
	{
		#region IStringManager Members

		public string ReplaceKeywords(string data, IDictionary<string, string> keywords)
		{
			var result = data ?? string.Empty;

			return keywords == null
				? result
				: keywords.Aggregate(result, (current, item) => current.Replace(item.Key, item.Value));
		}

		public string GetSyntacticKeywordValue(string keyword, int number)
		{
			if (string.IsNullOrWhiteSpace(keyword)) return string.Empty;

			switch (keyword)
			{
				case Constants.VICTORY_WORD_KEYWORD:
					return number == 1
						? string.Format("победа")
						: number >= 2 && number <= 4
							? string.Format("победы")
							: string.Format("побед");

				case Constants.MATCH_WORD_KEYWORD:
					return number == 1
						? string.Format("матч")
						: number >= 2 && number <= 4
							? string.Format("матча")
							: string.Format("матчей");

				case Constants.COMPLETED_WORD_KEYWORD:
					return number == 1
						? string.Format("завершен")
						: string.Format("завершены");

				case Constants.ONCE_WORD_KEYWORD:
					return number <= 1 || number > 4
						? string.Format("раз")
						: string.Format("раза");

				default:
					return string.Empty;
			}
		}

		#endregion
	}
}
